package shixhun;

import java.util.ArrayList;
import java.util.Iterator;

//ArrayList用法：添加删除，更新
//迭代
public class list {
    public static void main(String[] args) {
        ArrayList list1 = new ArrayList();
        list1.add("aaa");
        list1.add("asdasd");
        list1.add("cccc");
        System.out.println(list1);
        list1.add(1,"dd");
        System.out.println(list1);
        list1.remove("aaa");
        list1.remove(1);
        System.out.println(list1);
        list1.set(1,"zhiyin");
        System.out.println(list1);
        list1.add("linjun");
        list1.add("xilao");
        System.out.println(list1);
        System.out.println(list1.size());
        for(int i=0;i<list1.size();i++){
            //for循环迭代
            System.out.println(list1.get(i));
        }
        //增强性for循环
        for(Object str:list1){
            System.out.println(str);
        }
        System.out.println("分割线++++++++");
        //迭代
        Iterator it = list1.iterator();
        while (it.hasNext()){
            String str1=(String) it.next();
            System.out.println(str1);
        }
    }
}
